
module.exports = {
  sellIfMacdDownManyDays () {
    const kdjDiff15mOK = this.analysisInfo15m.kdjDiff < 0 ||
      (this.marketFlagInfo.indexIfMarketDownTrend && this.strategy === '1' && this.analysisInfo15m.isKdjDecline) ||
      (this.strategy === '1' && this.marketFlagInfo.ifMarket4hMacdEmaAllBad && this.marketFlagInfo.ifMarket4hMacdEmaAllBad && this.analysisInfo15m.isKdjDecline)
    if (
      this.analysisInfo15m.macdDownDays >= 22 &&
      this.analysisInfo15m.ema5W10B20Days >= 18 &&
      kdjDiff15mOK
    ) {
      if (
        (
          this.analysisInfo1h.macdDownDays >= 20 ||
          this.analysisInfo1h.ema5W10B20Days >= 20
        ) &&
        (
          this.analysisInfo4h.macdDownDays >= 20 ||
          this.analysisInfo4h.ema5W10B20Days >= 20
        )
      ) {
        // （确定性最强）
        this.setSell('sellIfMacdDownManyDays-1', {
          canReverse: true
        })
      }
    }
    // macd20天，如果510也有20天，然后当前是51020那也行
    if (
      this.analysisInfo15m.macdDownDays >= 20 &&
      this.analysisInfo15m.ema5B10Days >= 20 &&
      this.analysisInfo15m.ema5B10B20Days >= 1 &&
      kdjDiff15mOK
    ) {
      if (this.analysisInfo1h.macdDownDays >= 2) {
        this.setSell('sellIfMacdDownManyDays-2', {
          canReverse: true
        })
      }
    }
    if (
      this.analysisInfo15m.macdDownDays >= 20 &&
      this.analysisInfo15m.ema5W10B20Days >= 20 &&
      kdjDiff15mOK
    ) {
      if (this.strategy === '1') {
        this.setSell('sellIfMacdDownManyDays-3', {
          canReverse: true
        })
      }
    }
    if (
      this.analysisInfo1h.macdDownDays >= 20 &&
      this.analysisInfo1h.ema5W10B20Days >= 20 &&
      this.analysisInfo1h.kdjDiff < 0 &&
      kdjDiff15mOK
    ) {
      if (
        this.analysisInfo4h.macd < 0 &&
        this.analysisInfo4h.ema5B10B20Days >= 1 &&
        (this.analysisInfo1d.macd < 0 || this.analysisInfo1d.ema5W10B20Days >= 1)
      ) {
        this.setSell('sellIfMacdDownManyDays-4-1', {
          canReverse: true
        })
      }
    }
    if (
      this.analysisInfo15m.macdDownDays >= 30 &&
      this.analysisInfo15m.ema5W10B20Days >= 8 &&
      kdjDiff15mOK &&
      this.analysisInfo1h.macd < 0
    ) {
      this.setSell('sellIfMacdDownManyDays-6', {
        canReverse: true
      })
    }
    if (
      this.analysisInfo1h.macdDownDays >= 30 &&
      this.analysisInfo1h.ema5W10B20Days >= 8 &&
      this.analysisInfo1h.kdjDiff < 0 &&
      this.analysisInfo4h.macd < 0 &&
      kdjDiff15mOK
    ) {
      this.setSell('sellIfMacdDownManyDays-7', {
        canReverse: true
      })
    }
    if (
      this.analysisInfoFlag15m.countIfMacdDownTimes(38, 33) &&
      this.analysisInfo15m.macdDownDays >= 4 &&
      this.analysisInfo15m.ema5W10B20Days >= 30 &&
      kdjDiff15mOK
    ) {
      if (
        this.analysisInfo1h.macdDownDays >= 4 &&
        this.analysisInfo1h.ema5W10B20Days >= 4 &&
        this.analysisInfo1h.kdjDiff < 0
      ) {
        this.setSell('sellIfMacdDownManyDays-8', {
          canReverse: true
        })
      }
    }
    if (
      this.analysisInfoFlag15m.countIfMacdDownTimes(38, 33) &&
      this.analysisInfo15m.macdDownDays >= 3 &&
      this.analysisInfo15m.ema5W10B20Days >= 20 &&
      kdjDiff15mOK
    ) {
      if (
        this.analysisInfo1h.macdDownDays >= 4 &&
        this.analysisInfo1h.kdjDownDays >= 8
      ) {
        this.setSell('sellIfMacdDownManyDays-9', {
          canReverse: true
        })
      }
    }
    if (
      this.analysisInfo1h.macd < 0 &&
      this.analysisInfo1h.ema5W10B20Days >= 25 &&
      this.analysisInfo1h.kdjDiff < 0 &&
      this.analysisInfo15m.macd < 0 &&
      this.analysisInfo15m.ema5B10B20Days >= 1 &&
      kdjDiff15mOK
    ) {
      this.setSell('sellIfMacdDownManyDays-10', {
        canReverse: true
      })
    }
    if (
      !(this.marketInfo.macd4hGood || this.marketInfo.macd1hGood) &&
      this.analysisInfo1d.macd < 0 &&
      this.analysisInfo4h.ema5B10Days >= 1 &&
      (this.analysisInfo4h.ema5W10B20Days <= 1) &&
      (this.analysisInfo4h.close < this.analysisInfo4h.ema20) &&
      this.analysisInfo4h.macd < 0 &&
      this.analysisInfo4h.netChangeRatioDownDays >= 3 &&
      this.analysisInfo4h.kdjDownDays >= 3 &&
      this.analysisInfo4h.lastKdjUpDays >= 12 &&
      this.analysisInfo1h.macdDownDays >= 32 &&
      this.analysisInfo1h.kdjDownDays >= 10 &&
      this.analysisInfo1h.ema5W10B20Days >= 4 &&
      this.analysisInfo1h.ema5W10B20Days < 13 &&
      this.analysisInfo1h.lastEma5W10A20Days >= 32 &&
      this.analysisInfo15m.ema5W10B20Days >= 32 &&
      this.analysisInfo15m.ema5B10B20Days >= 1 &&
      this.analysisInfo15m.kdjDiff < 0
    ) {
      this.setSell('sellIfMacdDownManyDays-11', {
      })
      this.ifCanIgnoreNoSell = true
    }
  },
  sellIfEmaDownManyDays () {
    const kdjDiff15mOK = this.analysisInfo15m.kdjDiff < 0 ||
      (this.marketFlagInfo.indexIfMarketDownTrend && this.strategy === '1' && this.analysisInfo15m.isKdjDecline) ||
      (this.strategy === '1' && this.marketFlagInfo.ifMarket4hMacdEmaAllBad && this.marketFlagInfo.ifMarket4hMacdEmaAllBad && this.analysisInfo15m.isKdjDecline)
    if (
      this.analysisInfo15m.ema5W10B20Days >= 35 &&
      this.analysisInfo15m.macd < 0 &&
      this.analysisInfo15m.macdDownDays <= 2 &&
      kdjDiff15mOK
    ) {
      this.setSell('sellIfEmaDownManyDays-1', {
        canReverse: true
      })
    }
    if (
      this.analysisInfo1h.ema5W10B20Days >= 35 &&
      this.analysisInfo1h.macd < 0 &&
      this.analysisInfo1h.macdDownDays <= 2 &&
      this.analysisInfo15m.ema5W10B20Days >= 4 &&
      this.analysisInfo15m.macd < 0 &&
      kdjDiff15mOK
    ) {
      this.setSell('sellIfEmaDownManyDays-2', {
        canReverse: true
      })
    }
    if (
      (
        this.analysisInfo1h.macdDownDays >= 30 &&
        this.analysisInfo1h.ema5W10B20Days >= 15
      ) ||
      (
        this.analysisInfo1h.macdDownDays >= 15 &&
        this.analysisInfo1h.ema5W10B20Days >= 30
      )
    ) {
      if (
        this.analysisInfo15m.ema5W10B20Days >= 40 &&
        kdjDiff15mOK &&
        this.analysisInfo15m.isEm5Decline &&
        this.analysisInfo15m.isEm10Decline &&
        this.analysisInfo15m.isEm20Decline
      ) {
        this.setSell('sellIfEmaDownManyDays-3', {
          canReverse: true
        })
      }
    }
    if (
      this.analysisInfoFlag1h.countIf5W10A20Times(35, 33) &&
      this.analysisInfo1h.ema5W10B20Days >= 4 &&
      this.analysisInfo1h.kdjDiff < 0 &&
      this.analysisInfo1h.macd < 0 &&
      this.analysisInfo1h.isEm5Decline &&
      this.analysisInfo1h.isEm10Decline &&
      this.analysisInfo1h.isEm20Decline
    ) {
      if (
        this.analysisInfo15m.isEm5Decline &&
        this.analysisInfo15m.isEm10Decline &&
        this.analysisInfo15m.isEm20Decline &&
        this.analysisInfo15m.ema5W10B20Days >= 1 &&
        this.analysisInfo15m.macd < 0 &&
        kdjDiff15mOK
      ) {
        this.setSell('sellIfEmaDownManyDays-4', {
          canReverse: true
        })
      }
    }
  },
  sellIfUpManyDaysTransDown () {
    let avRate = this.analysisInfo15m.before10DaysAvMaxWave
    if (avRate < 0.3) {
      avRate = 0.3
    }
    if (
      this.analysisInfo15m.netChangeRatio < 0 &&
      this.analysisInfo15m.highLowRate / avRate > 12 &&
      (Math.abs(this.analysisInfo15m.netChangeRatio) / this.analysisInfo15m.highLowRate) > 0.9 &&
      this.analysisInfo15m.macd < 0 &&
      this.analysisInfo15m.kdjDiff < 0 &&
      this.analysisInfo15m.close < this.analysisInfo15m.ema20 &&
      !this.marketFlagInfo.isMarketBigGoodUp
    ) {
      if (
        this.analysisInfo15m.lastMacdUpDays >= 20 &&
        (
          this.analysisInfo15m.ema5W10A20Days >= 20 ||
          this.analysisInfo15m.lastEma5W10A20Days >= 20
        ) &&
        (
          this.lastEmaInfo15m.ema5 > this.lastEmaInfo15m.ema10 &&
          this.lastEmaInfo15m.ema10 > this.lastEmaInfo15m.ema20
        )
      ) {
        this.setSell('sellIfUpManyDaysTransDown-1', {
          rate: 1
        })
      }
    }
  },
  sellIfCrash15m () {
    if (this.marketInfo && this.marketInfo.crash15m) {
      if (
        this.analysisInfo15m.macd < 0 &&
        this.analysisInfo15m.kdjDiff < 0 &&
        this.analysisInfo15m.ema5W10B20Days >= 1
      ) {
        if (
          this.analysisInfo1h.macdDownDays >= 5 &&
          this.analysisInfo1h.ema5W10B20Days >= 10
        ) {
          if (this.strategy === '2') {
            // 简直就是反向指标
            this.setSell('sellIfCrash15m-1', {
              canReverse: true
            })
          }
        }
        if (
          this.analysisInfo1h.macdDownDays >= 10 &&
          this.analysisInfo1h.ema5W10B20Days >= 5
        ) {
          if (this.strategy === '2') {
            this.setSell('sellIfCrash15m-2', {
              canReverse: true
            })
          }
        }
      }
      if (this.marketInfo.onlyKong) {
        if (
          this.analysisInfo15m.macd < 0 &&
          this.analysisInfo15m.kdjDiff < 0 &&
          this.analysisInfo15m.ema5W10B20Days >= 1 &&
          this.analysisInfo1h.macd < 0 &&
          this.analysisInfo1h.kdjDiff < 0 &&
          this.analysisInfo1h.ema5W10B20Days >= 1 &&
          // 第一波共振
          this.analysisInfo1h.ema5W10B20Days <= 10 &&
          this.analysisInfo15m.ema5W10B20Days <= 10 &&
          this.marketInfo.max50AvRate < 0
        ) {
          if (this.strategy === '2') {
            this.setSell('sellIfCrash15m-3', {
              canReverse: true
            })
          }
        }
      }
    }
    if (this.marketFlagInfo.ifMarket15mAllBad3Days) {
      // 3天了
      if (this.strategy === '2') {
        if (
          this.analysisInfo15m.ema5W10B20Days >= 20 &&
          this.analysisInfo15m.macd < 0 &&
          this.analysisInfo15m.kdjDiff < 0 &&
          this.analysisInfo1h.ema5W10B20Days >= 4 &&
          this.analysisInfo1h.macd < 0 &&
          this.analysisInfo1h.kdjDiff < 0
        ) {
          this.setSell('sellIfCrash15m-4', {
            canReverse: true
          })
          this.ifCanIgnoreNoSell = true
          this.ifCanIgnoreNobuy = true
        }
        if (
          this.analysisInfo15m.ema5W10B20Days >= 12 &&
          this.analysisInfo15m.macd < 0 &&
          this.analysisInfo15m.kdjDiff < 0 &&
          this.analysisInfo1h.ema5W10B20Days >= 20 &&
          this.analysisInfo1h.macd < 0 &&
          this.analysisInfo1h.kdjDiff < 0
        ) {
          this.setSell('sellIfCrash15m-4-1', {
            canReverse: true
          })
          this.ifCanIgnoreNoSell = true
          this.ifCanIgnoreNobuy = true
        }
      }
    }
  },
  sellIfMarket () {
    if (!this.marketInfo) {
      return
    }
    if (this.marketInfo.likeKong || this.marketInfo.onlyKong) {
      if (
        this.analysisInfo15m.isEm5Decline &&
        this.analysisInfo15m.isEm10Decline &&
        this.analysisInfo15m.isEm20Decline &&
        this.analysisInfo15m.ema5W10B20Days >= 20 &&
        this.analysisInfo15m.ema5B10B20Days <= 4 &&
        this.analysisInfo15m.ema5B10B20Days >= 1 &&
        this.analysisInfo15m.macd < 0 &&
        this.analysisInfo15m.kdjDiff < 0
      ) {
        if (
          this.analysisInfo1h.macdDownDays >= 6 &&
          this.analysisInfo1h.ema5B10B20Days >= 4
        ) {
          this.setSell('sellIfMarket-1', {
            canReverse: true
          })
        }
      }
    }
  },
  sellIfHighFrequency () {
    if (
      this.analysisInfo1h.kdjDownDays >= 8 &&
      this.analysisInfo1h.macdDownDays >= 8 &&
      this.analysisInfo1h.ema5B10B20Days >= 1
      // 卖出的时候不要判断了
      // (
      //   this.marketFlagInfo.ifMarket15mMacdEmaAllBad ||
      //   this.marketFlagInfo.ifMarket15mMacdEmaAllGood
      // )
    ) {
      if (
        this.analysisInfo15m.macd < 0 &&
        this.analysisInfo15m.kdjDiff < 0 &&
        this.analysisInfo15m.ema5B10B20Days >= 1
      ) {
        if (this.strategy === '1') {
          if (
            this.analysisInfo1h.macdDownKeepInfo.rrncs < 0.3 ||
            this.analysisInfo1h.macdDownKeepInfo.mdrr > 0.5 ||
            this.analysisInfo1h.kdjDownKeepInfo.rrncs < 0.3 ||
            this.analysisInfo1h.kdjDownKeepInfo.mdrr > 0.5
          ) {
            return
          }
          this.setSell('sellIfHighFrequency-1', {
            canReverse: true
          })
        } else {
          this.setSell('sellIfHighFrequency-2', {
            canReverse: true
          })
        }
      }
    }
  }
}
